package com.wzh.core.api;

import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * @description: 负载均衡
 * @author: wangzouhuax
 */
public interface LoadBalance<T> {

    /**
     * 多个服务，选择一个使用
     */
    T choose(List<T> urls);

    LoadBalance LOAD_BALANCE_DEFAULT = new LoadBalance<String>() {
        @Override
        public String choose(List<String> urls) {
            if (CollectionUtils.isEmpty(urls)) {
                return null;
            }
            return urls.get(0);
        }
    };
}
